package com.qst.service;

import com.qst.mapper.EquipmentMapper;
import com.qst.pojo.Equipment;
import com.qst.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassNmae: EquipmentService
 * @Author: 邓嘉顺
 * @Description:
 */
@Service
public class EquipmentService {
    @Autowired
    EquipmentMapper equipmentMapper;

    public List<Equipment> queryAllEquipment(String equipmentName) {
        return equipmentMapper.queryAllEquipment(equipmentName);
    }

    public int getAllCount() {
        return equipmentMapper.getAllCount();
    }

    public Result addEquipment(Equipment equipment) {

        int  row = equipmentMapper.addEquipment(equipment);

        if(row!=1){
            return new Result(100,"添加失败");
        }
        return new Result(200,"添加成功");
    }

    public Result delBatch(Integer[] ids) {
        if(ids==null || ids.length==0){
            return new Result(100,"至少选中一条记录");
        }
        int row=equipmentMapper.delBatch(ids);
//        有多少id就影响多少行,删除失败
        if(row!=ids.length){
            return  new Result(100,"异常情况");
        }
//        删除成功
        return new Result(200,"删除成功");
    }

    public Result EditEquipment(Integer id, String field, String value) {
        int row =equipmentMapper.EditEquipment(id,field,value);

        if(row!=1){

            return new Result(100,"更新失败");

        }

        return new Result(200,"更新成功");
    }
//    public void addEquipment02(String imgStr) {
//        return equipmentMapper.addEquipment02(imgStr);
//    }
}
